package com.example.boot6rabbitmq.consumer;


import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class DlMessageConsumer {


    /**
     * 监听死信队列，处理延迟消息
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "dl.message"),
            exchange = @Exchange(value = "binding-dl", type = ExchangeTypes.TOPIC))
    )
    public void process(String msg, Channel channel, Message message) throws IOException {

        System.out.println("延迟消息：{}"+msg);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }

}
